/*
 * =====================================================================================
 *
 *       Filename:  cipher_1026.cc
 *
 *    Description:  find the encoded message 
 *
 *        Version:  1.0
 *
 *        Created:  09/19/2012 07:41:31 PM
 *
 * =====================================================================================
 */
#include	<stdio.h>
#include	<string.h>
#include	<algorithm>

const int nmax = 200;

int keyTable[nmax];
char msg[nmax+4];
char enmsg[nmax+4];

char* getEncodedMsg(char *dst, char *src, int k, int n) 
{
    char *enPtr = dst;
    char *ptr = src;
    while (k--) {
        for (int i = 0;i < n; ++i)
            enPtr[keyTable[i]] = ptr[i];
        std::swap(enPtr, ptr);
    }
    return ptr;
}

int main(int argc, char *argv[])
{
    int n, K;
    while (scanf("%d", &n) == 1 && n) {
        for (int i = 0; i < n; ++i) {
            scanf("%d", &keyTable[i]);
            --keyTable[i];
        }
        while (scanf("%d", &K) == 1 && K) {
            getchar();
            fgets(msg, sizeof(msg), stdin);
            int len = strlen(msg);
            if (msg[len-1] == '\n') {
                --len;
                msg[len] = '\0';
            }
            for (int j = len; j < n; ++j)
                msg[j] = ' ';
            msg[n] = '\0';
            memset(enmsg, 0x00, sizeof(enmsg));
            char *ptr = getEncodedMsg(enmsg, msg, K, n);
            printf ( "%s\n", ptr);
        }
    }
    return 0;
}
